<template>
    <!-- 分包商奖惩--编辑 -->
    <div class="e-form">
        <div
            class="tabs warningTabs"
            v-if="Object.keys(basicFormData).length != 0"
        >
            <el-tabs
                tab-position="left"
                v-model="tabsName"
                @tab-click="onChangeTab"
            >
                <!-- 基本信息 -->
                <el-tab-pane
                    label="基本信息"
                    name="baseInfo"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="处罚明细"
                    name="punishDetail"
                    :disabled="clickTabFlag"
                    v-if="basicFormData.rewardsOrPunishmentName == '惩罚'"
                ></el-tab-pane>
                <el-tab-pane
                    label="奖励明细"
                    name="rewardDetails"
                    :disabled="clickTabFlag"
                    v-else
                ></el-tab-pane>
                <el-tab-pane
                    label="附件信息"
                    name="accessory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>
                <el-tab-pane
                    label="审核历史"
                    name="auditHistory"
                    :disabled="clickTabFlag"
                ></el-tab-pane>

                <div>
                    <!-- 基本信息 -->
                    <div id="baseInfoCon" class="con">
                        <div class="e-form">
                            <div class="tabs">
                                <div class="tabs-title" id="baseInfo">
                                    基本信息
                                </div>
                                <div style="width: 100%" class="form">
                                    <el-form
                                        :model="basicFormData"
                                        ref="basicFormData"
                                        :rules="rules"
                                        label-width="150px"
                                    >
                                        <BillTop
                                            title="分包商奖惩编辑"
                                            @cancel="handleClose"
                                        ></BillTop>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="分包商名称"
                                                    prop="outerName"
                                                >
                                                    <el-input
                                                        v-model="
                                                            basicFormData.outerName
                                                        "
                                                        placeholder="请填写"
                                                        @change="
                                                            outerNameChange
                                                        "
                                                    >
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-icon-document-copy
                                                            "
                                                            @click="onFbUnit"
                                                        ></i>
                                                    </el-input>
                                                    <el-button
                                                        v-if="
                                                            !basicFormData.isOuterUnit
                                                        "
                                                        style="
                                                            background-color: rgb(22,155,213);
                                                            color: #fff;
                                                            margin-left: 20px;
                                                        "
                                                        @click="onSelect1"
                                                        >查看</el-button
                                                    >
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="统一社会信用代码"
                                                    prop="creditCode"
                                                >
                                                    <el-input
                                                        :disabled="isDisable"
                                                        v-model="
                                                            basicFormData.creditCode
                                                        "
                                                        placeholder="请填写"
                                                        maxlength="18"
                                                    ></el-input>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    v-if="
                                                        basicFormData.isOuterUnit
                                                    "
                                                    label="合同名称:"
                                                >
                                                    <span> {{ '- -' }}</span>
                                                </el-form-item>
                                                <el-form-item
                                                    v-else
                                                    label="合同名称"
                                                >
                                                    <el-input
                                                        v-model="
                                                            basicFormData.contractName
                                                        "
                                                        readonly
                                                        placeholder="请选择"
                                                    >
                                                        <i
                                                            slot="suffix"
                                                            class="
                                                                el-icon-document-copy
                                                            "
                                                            @click="onContract"
                                                        ></i>
                                                    </el-input>
                                                    <el-button
                                                        style="
                                                            background-color: rgb(22,155,213);color: #fff; margin-left: 20px;
                                                        "
                                                        @click="onSelect2"
                                                        >查看</el-button
                                                    >
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="分包商类型"
                                                    prop="outerTypeKey"
                                                >
                                                    <el-checkbox
                                                        :indeterminate="
                                                            isIndeterminate
                                                        "
                                                        v-model="checkAll"
                                                        @change="
                                                            handleCheckAllChange
                                                        "
                                                        style="
                                                            margin-right: 20px;
                                                        "
                                                        :disabled="
                                                            !basicFormData.isOuterUnit
                                                        "
                                                        >全选</el-checkbox
                                                    >
                                                    <el-checkbox-group
                                                        v-model="
                                                            basicFormData.outerTypeKey
                                                        "
                                                        :disabled="
                                                            !basicFormData.isOuterUnit
                                                        "
                                                        @change="
                                                            handleCheckedCitiesChange
                                                        "
                                                    >
                                                        <el-checkbox
                                                            v-for="item in typeList"
                                                            :key="item.kvId"
                                                            :label="item.kvKey"
                                                            :value="item.kvId"
                                                            style="
                                                                margin-top: 5px;
                                                            "
                                                        ></el-checkbox>
                                                    </el-checkbox-group>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="奖惩类型"
                                                    prop="rewardsOrPunishmentName"
                                                >
                                                    <el-radio
                                                        v-for="item in rewardsOrPunishmentList"
                                                        :key="item.kvId"
                                                        :disabled="
                                                            item.disabled
                                                        "
                                                        :label="item.kvKey"
                                                        :value="
                                                            basicFormData.rewardsOrPunishmentName
                                                        "
                                                        @click.native="
                                                            onRAPType(
                                                                $event,
                                                                item.kvKey
                                                            )
                                                        "
                                                    ></el-radio>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="奖惩等级或得分"
                                                >
                                                    {{ basicFormData.score }}
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row
                                            v-if="
                                                basicFormData.rewardsOrPunishmentName ==
                                                '惩罚'
                                            "
                                        >
                                            <el-col :span="12">
                                                <el-form-item
                                                    label="开始日期"
                                                    prop="startDate"
                                                >
                                                    <el-date-picker
                                                        v-model="
                                                            basicFormData.startDate
                                                        "
                                                        type="date"
                                                        placeholder="选择日期"
                                                        :clearable="false"
                                                    >
                                                    </el-date-picker>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="结束日期">
                                                    <el-date-picker
                                                        v-if="isLifelong"
                                                        v-model="
                                                            basicFormData.endDate
                                                        "
                                                        type="date"
                                                        placeholder="选择日期"
                                                        readonly
                                                        :clearable="false"
                                                    >
                                                    </el-date-picker>
                                                    <span v-else>{{
                                                        '终身'
                                                    }}</span>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                        <el-row>
                                            <el-form-item
                                                label="评价意见"
                                                prop="opinion"
                                            >
                                                <el-input
                                                    v-model="
                                                        basicFormData.opinion
                                                    "
                                                    type="textarea"
                                                    placeholder="请输入内容"
                                                    :rows="2"
                                                ></el-input>
                                            </el-form-item>
                                        </el-row>
                                        <el-row>
                                            <el-form-item label="备注">
                                                <el-input
                                                    type="textarea"
                                                    :rows="2"
                                                    placeholder="请输入内容"
                                                    v-model="
                                                        basicFormData.remarks
                                                    "
                                                >
                                                </el-input>
                                            </el-form-item>
                                        </el-row>
                                        <el-row>
                                            <el-col :span="12">
                                                <el-form-item label="机构">
                                                    {{ basicFormData.orgName }}
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span="12">
                                                <el-form-item label="状态">
                                                    {{
                                                        statusLable(
                                                            basicFormData.state
                                                        )
                                                    }}
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-form>
                                </div>
                            </div>
                        </div>

                        <!-- ------------------------------------------------------------------------------------- -->
                    </div>

                    <div
                        id="punishDetailCon"
                        class="con"
                        v-show="basicFormData.rewardsOrPunishmentName == '惩罚'"
                    >
                        <div class="tabs-title" id="punishDetail">处罚明细</div>
                        <!-- 处罚明细 -->
                        <div
                            style="margin-bottom: 20px"
                            class="errorMsg"
                            v-if="errorMsg1.length > 0"
                        >
                            <span
                                style="display: block"
                                v-for="(item, index) in errorMsg1"
                                :key="index"
                            >
                                {{ item }}
                            </span>
                        </div>
                        <div>
                            <el-table
                                :data="punishDetailTable"
                                :max-height="$store.state.tableHeight"
                                ref="multipleTable"
                                border
                                row-key="dtlId"
                                :row-class-name="rowClassNameFun"
                                :header-row-class-name="headerRowClassName"
                                size="mini"
                                class="table"
                                style="width: 100%"
                                @select="selectFun"
                                @selection-change="selectionClick"
                                @select-all="selectAllFun"
                                :header-cell-style="{ background: '#fafafa' }"
                                v-sortTable="{
                                    tableData: punishDetailTable,
                                    _this: this,
                                    ref: 'multipleTable'
                                }"
                            >
                                <el-table-column type="selection" width="55">
                                </el-table-column>
                                <el-table-column
                                    key="sortIndex"
                                    prop="sortIndex"
                                    label="序号"
                                    width="200"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="dtlName"
                                    label="处罚内容"
                                    min-width="700"
                                    key="dtlName"
                                >
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                    <!-- 奖励明细 -->
                    <div
                        style="margin-bottom: 20px"
                        class="errorMsg"
                        v-if="errorMsg2.length > 0"
                    >
                        <span
                            style="display: block"
                            v-for="(item, index) in errorMsg2"
                            :key="index"
                        >
                            {{ item }}
                        </span>
                    </div>
                    <div
                        id="rewardDetailsCon"
                        class="con"
                        v-show="basicFormData.rewardsOrPunishmentName == '奖励'"
                    >
                        <div class="tabs-title" id="rewardDetails">
                            奖励明细
                        </div>
                        <div class="e-table">
                            <el-table
                                :data="rewardData"
                                border
                                ref="table"
                                style="width: 100%"
                                class="table"
                                :max-height="$store.state.tableHeight"
                                @cell-mouse-enter="cellMouseEnter"
                                @cell-mouse-leave="cellMouseLeave"
                                :cell-class-name="cellClsNm"
                                v-sortTable="{
                                    tableData: rewardData,
                                    _this: this,
                                    ref: 'table'
                                }"
                                row-key="dtlId"
                                :tree-props="{
                                    children: 'children',
                                    hasChildren: 'hasChildren'
                                }"
                            >
                                >
                                <el-table-column
                                    key="selection2"
                                    prop="sortIndex"
                                    label="序号"
                                    width="80"
                                >
                                </el-table-column>
                                <el-table-column
                                    key="content"
                                    prop="dtlName"
                                    label="检查内容"
                                    min-width="300"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="score"
                                    label="规定分值"
                                    width="120"
                                >
                                </el-table-column>
                                <el-table-column
                                    prop="inspectionRecord"
                                    label="检查记录"
                                    min-width="300"
                                >
                                    <template slot-scope="scope">
                                        <el-input
                                            v-if="
                                                scope.row.children == null ||
                                                scope.row.children.length == 0
                                            "
                                            v-model="scope.row.inspectionRecord"
                                        ></el-input>
                                        <span v-else>{{
                                            scope.row.inspectionRecord
                                        }}</span>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                    prop="scoreResult"
                                    label="实得分值"
                                    width="150"
                                >
                                    <template slot-scope="scope">
                                        <el-input
                                            @change="calculation"
                                            v-if="
                                                scope.row.children == null ||
                                                scope.row.children.length == 0
                                            "
                                            type="number"
                                            v-model="scope.row.scoreResult"
                                        ></el-input>
                                        <span v-else>{{
                                            scope.row.scoreResult
                                        }}</span>
                                    </template>
                                </el-table-column>
                            </el-table>
                        </div>
                    </div>
                    <div
                        style="margin-bottom: 20px"
                        class="errorMsg"
                        v-if="errorMsg3.length > 0"
                    >
                        <span
                            style="display: block"
                            v-for="(item, index) in errorMsg3"
                            :key="index"
                        >
                            {{ item }}
                        </span>
                    </div>
                    <!-- 附件信息 -->
                    <div id="WarehouseCon" class="con">
                        <div class="tabs-title" id="accessory">附件信息</div>
                        <div class="errorMsg" v-if="errorMsg.length > 0">
                            <span
                                style="display: block"
                                v-for="(item, index) in errorMsg"
                                :key="index"
                            >
                                {{ item }}
                            </span>
                        </div>
                        <div class="e-table">
                            <AttachComp
                                :bucketName="bucketName"
                                :relationId="billid"
                                ref="accessory"
                            ></AttachComp>
                        </div>
                    </div>
                    <!-- 审核历史 -->
                    <div id="auditHistoryCon" class="con">
                        <div class="tabs-title" id="auditHistory">审核历史</div>
                        <ComExaHistory
                            :billType="6046"
                            @getAuditHistory="getAuditHistory"
                            :tableData="tableData"
                            ref="ComExaHistory"
                        />
                    </div>
                </div>
            </el-tabs>
        </div>
        <div id="seat" :style="{ height: seatHeight + 'px' }"></div>
        <div class="buttons">
            <ComExaButtons
                :auditState="auditState"
                :state="basicFormData.state"
                @exas="exas"
            />
            <el-button @click="handleClose" size="small">取消</el-button>
        </div>
    </div>
</template>

<script>
import '@/utils/jquery.scrollTo.min'
import { mapMutations } from 'vuex'
import {
    showSuccessPop,
    selectDataClient,
    openAppClient,
    throttle,
    showLoading,
    hideLoading
} from '@/utils/common'
import subcontractorRAP from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractorRAP.js'
import { creditTemplate, creditEvaluationType } from '@/api/base/outsourcer'
import AttachComp from '@/components/common/attachIndex'
//审核历史
import ComExaHistory from '@/components/common/exaHistory.vue'
import ComExaButtons from '@/components/common/exaButtons'
//审核
import examine from '@/api/OutsourcingartyAdmin/subcontractorAdmin/examine.js'
import subcontractorChange from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractorChange.js'
import { getBaseName } from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractor.js'
import call from '@/api/OutsourcingartyAdmin/getAllType.js'
import { creditCodeVerification } from '@/utils/rules'
import { toVoid } from '@/api/OutsourcingartyAdmin/subcontractorAdmin/subcontractor.js'
export default {
    components: {
        AttachComp,
        ComExaHistory,
        ComExaButtons
    },
    data () {
        return {
            bucketName: 'OutsourcingartyAdmin',
            tabsName: 'baseInfo',
            form: {
                name: '',
                region: '',
                date1: '',
                date2: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            },
            tableData: [],
            value: '',
            textarea: '',
            screenWidth: 0,
            screenHeight: 0,
            lastConHeight: 0,
            clickTabFlag: false, // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            //基本信息表单数据
            basicFormData: {
                outerName: '', //分包商名称
                creditCode: '', //统一社会信用代码
                contractName: '', //合同名称
                rewardsOrPunishment: '', //奖惩类型id
                rewardsOrPunishmentName: '', //奖惩类型名称
                startDate: '', //开始日期
                endDate: '', //结束日期
                opinion: '', //评价意见
                score: '', //奖惩等级或得分
                state: 0, //状态
                orgName: '', //机构
                inspectionRecord: '', //检查记录
                id: '', //处罚ID
                manageOrgId: '', //管理单位ID
                manageOrgName: '', //管理单位
                orgId: '', //机构ID
                outerTypeKey: [], //	外包方类型名称
                outerTypeValue: [], //外包方类型ID
                remark: '', //备注
                address: '', //	单位住所
                billDate: '', //单据时间
                billNo: '', //供应商处罚编号
                contactTel: '', //联系电话
                contractId: '', //合同id
                deputy: '', //法人代表
                evagrade: 0, //本次评价等级
                isUsed: 0, //	是否启用
                oldEvagrade: '', //原来信用等级
                outerId: '', //机构ID
                projectLeader: '', //	项目负责人
                qualificationLevelId: '', //资质等级ID
                qualificationLevelName: '', //资质等级
                registerCapital: 0, //注册资本
                result: '', //评价结论
                workId: '', //	作业ID
                type: '0' //分包商
            },
            type: '', //合同类型
            contractId: '', //合同id
            typeList: [], //类型列表
            rewardsOrPunishmentList: [], //奖惩类型列表
            punishDetailTable: [], //惩罚列表数据
            rewardData: [], //奖励数据
            isIndeterminate: true,
            creditEvaluationTypeTable: {}, //不合格惩罚年限数据
            id: '', //单据id
            isSkip: false, //是否跳转
            checkAll: false, //是否全选
            auditState: {}, //按钮状态
            isLifelong: true, //是否终身
            penaltyDetails: [], //选中的处罚值
            winEvent: {}, //保存事件，跳转页面的时候，结束事件，优化性能
            errorList: [], //控制导航栏感叹号的显示
            errorMsg: [], //验证数组
            isNum: 0, //C级处罚年限
            isDisable: false, //库内单位禁用统一社会信用代码
            isRequired: false,
            errorMsg1: [], //惩罚
            errorMsg2: [], //奖励
            errorMsg3: [], //附件
            // 审核对象
            commit: {
                billId: '', //	单据Id
                billType: 6046, //单据编码
                freeNextUnitIndex: 0, //下一步审核步骤
                freeNextUser: '', //	下一步审核人ID
                isPass: true, //审核是否通过
                isShareInAudit: true, //是否共享审核节点
                opinion: '' //审核意见
            },
            isSend: false, //是否可保存
            // 验证
            rules: {
                // 统一社会信用代码
                creditCode: [
                    {
                        required: true,
                        validator: creditCodeVerification,
                        trigger: 'blur'
                    }
                ],
                //分包商名称
                outerName: [
                    {
                        required: true,
                        message: '请选择分包商名称',
                        trigger: 'blur'
                    }
                ],
                //分包商类型
                outerTypeKey: [
                    { required: true, message: '请选择类型', trigger: 'change' }
                ],
                //奖惩类型
                rewardsOrPunishmentName: [
                    { required: true, message: '请选择类型', trigger: 'change' }
                ],
                //开始时间
                startDate: [
                    {
                        required: true,
                        message: '请选择开始时间',
                        trigger: 'change'
                    }
                ],
                //评价意见
                opinion: [
                    {
                        required: true,
                        message: '请输入评价意见',
                        trigger: 'blur'
                    }
                ]
            }
        }
    },
    computed: {
        // 填补底部空白，以使高度够滚动
        seatHeight () {
            return this.screenHeight - 240 - this.lastConHeight
        },
        // 判断状态
        statusLable () {
            return param => {
                const state = this.$store.state.equip.equipData.state
                const obj = state.find(x => x.value == param)
                if (obj !== undefined) {
                    return obj.label
                }
            }
        }
    },
    created () {
        this.billid = this.$route.query.billid
        this.getBasicData() //进入页面就获取基本信息数据
        this.getTypeData() //进入页面获取类型选择框数据
        this.getCreditEvaluationType() //获取不合格处罚年限
        this.getCurrentUnitInfo() //获取流程按钮
    },
    watch: {
        //给错误标签加上提醒
        errorList: newData => {
            const tabs = document.querySelectorAll('.el-tabs__item')
            tabs.forEach(DOM => {
                const { childNodes } = DOM
                if (childNodes.length > 1) {
                    DOM.removeChild(childNodes[1])
                }
            })
            newData.forEach(item => {
                const itemDom = document.querySelector(`#tab-${item}`)
                var element = document.createElement('i')
                element.className = 'el-icon-warning-outline warning'
                itemDom.appendChild(element)
            })
        }
    },

    mounted () {
        // 获取最后一个内容区域的高度，计算底部空白
        this.getLastConHeight()
        // 保存所有tabName
        const arr = ['baseInfo', 'punishDetail', 'accessory', 'auditHistory']
        let $idsTop = []
        this.tabArr = arr
        const onScroll = () => {
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            if (this.clickTabFlag) {
                return
            }
            if (!$idsTop[$idsTop.length - 1]) {
                $idsTop = arr.map(item => {
                    const $item = document.getElementById(item)
                    let itemTop = null
                    if ($item) {
                        itemTop = $item.offsetTop
                    }
                    return itemTop
                })
            }
            const scrollTop =
                document.documentElement.scrollTop || document.body.scrollTop
            // 倒序查找
            let curLocal = 0
            for (let len = $idsTop.length, i = len - 1; i >= 0; i--) {
                let item = $idsTop[i]
                if (scrollTop + 1 >= item) {
                    curLocal = i
                    break
                }
            }
            // 设置对应tabName
            this.tabsName = arr[curLocal]
        }
        this.winEvent.onScroll = onScroll
        window.addEventListener('scroll', this.winEvent.onScroll)
        this.screenWidth =
            document.documentElement.clientWidth - this.topHeight
        this.screenHeight =
            document.documentElement.clientHeight - this.topHeight
        const onResize = () => {
            this.screenWidth = document.documentElement.clientWidth
            this.screenHeight = document.documentElement.clientHeight
            $idsTop = arr.map(item => {
                const itemTop = document.getElementById(item).offsetTop
                return itemTop
            })
        }
        this.winEvent.onResize = throttle(onResize, 500)
        window.addEventListener('resize', this.winEvent.onResize)
    },
    beforeDestroy () {
        window.removeEventListener('scroll', this.winEvent.onScroll)
        window.removeEventListener('resize', this.winEvent.onResize)
    },
    methods: {
        /**
         * 处理惩罚
         */
        //初始化数据
        initData (data) {
            data.forEach(item => {
                item.isCheck = false //默认为不选中
                if (item.children && item.children.length) {
                    this.initData(item.children)
                }
            })
        },

        // 复选框选中事件
        selectFun (selection, row) {
            this.setRowIsSelect(row)
        },
        // 复选框点击事件
        setRowIsSelect (row) {
            //当点击父级点复选框时，当前的状态可能为未知状态，所以当前行状态设为false并选中，即可实现子级点全选效果
            if (row.isCheck === null) {
                row.isCheck = false
                this.$refs.multipleTable.toggleRowSelection(row, true)
            }
            row.isCheck = !row.isCheck
            let that = this
            // 选中父级时候，选中父级及全部子集
            function selectAllChildrens (data) {
                data.forEach(item => {
                    item.isCheck = row.isCheck
                    that.$refs.multipleTable.toggleRowSelection(
                        item,
                        row.isCheck
                    )
                    if (item.children && item.children.length) {
                        selectAllChildrens(item.children)
                    }
                })
            }
            // 判断子集是否全部选中
            function getSelectStatus (selectStatuaArr, data) {
                data.forEach(childrenItem => {
                    selectStatuaArr.push(childrenItem.isCheck)
                    if (childrenItem.children && childrenItem.children.length) {
                        getSelectStatus(selectStatuaArr, childrenItem.children)
                    }
                })
                return selectStatuaArr
            }
            // 判断点击的是哪个节点
            function getLevelStatus (row) {
                //如果当前节点的parantId =0 并且有子节点，则为1
                //如果当前节点的parantId !=0 并且子节点没有子节点 则为3
                if (row.parentId == 0) {
                    if (row.children && row.children.length) {
                        return 1
                    } else {
                        return 4
                    }
                } else {
                    if (!row.children || !row.children.length) {
                        return 3
                    } else {
                        return 2
                    }
                }
            }
            let result = {}
            //获取明确的节点
            function getExplicitNode (data, parentId) {
                data.forEach(item => {
                    if (item.dtlId == parentId) {
                        result = item
                    }
                    if (item.children && item.children.length) {
                        getExplicitNode(item.children, parentId)
                    }
                })
                return result
            }
            // 选中的子集，来操作父节点
            function operateLastLeve (row) {
                //操作的是子节点  1、获取父节点  2、判断子节点选中个数，如果全部选中则父节点设为选中状态，如果都不选中，则为不选中状态，如果部分选择，则设为不明确状态
                let selectStatuaArr = []
                let item = getExplicitNode(
                    that.punishDetailTable,
                    row.parentId
                )
                selectStatuaArr = getSelectStatus(
                    selectStatuaArr,
                    item.children
                )
                if (
                    // 全选
                    selectStatuaArr.every(selectItem => {
                        return true == selectItem
                    })
                ) {
                    item.isCheck = true
                    that.$refs.multipleTable.toggleRowSelection(item, true)
                } else if (
                    // 全不选
                    selectStatuaArr.every(selectItem => {
                        return false == selectItem
                    })
                ) {
                    item.isCheck = false
                    that.$refs.multipleTable.toggleRowSelection(item, false)
                } else {
                    item.isCheck = null
                }
                //则还有父级
                if (item.parentId != 0) {
                    operateLastLeve(item)
                }
            }
            //判断操作的是子级点复选框还是父级点复选框，如果是父级点，则控制子级点的全选和不全选

            //1、只是父级 2、既是子集，又是父级 3、只是子级
            let levelSataus = getLevelStatus(row)
            if (levelSataus == 1) {
                selectAllChildrens(row.children)
            } else if (levelSataus == 2) {
                selectAllChildrens(row.children)
                operateLastLeve(row)
            } else if (levelSataus == 3) {
                operateLastLeve(row)
            }
        },
        // 检测表格数据是否全选
        checkIsAllSelect () {
            this.oneProductIsSelect = []
            this.punishDetailTable.forEach(item => {
                this.oneProductIsSelect.push(item.isCheck)
            })
            //判断一级产品是否是全选.如果一级产品全为true，则设置为取消全选，否则全选
            let isAllSelect = this.oneProductIsSelect.every(
                selectStatusItem => {
                    return true == selectStatusItem
                }
            )
            return isAllSelect
        },
        // 表格全选事件
        selectAllFun (selection) {
            let isAllSelect = this.checkIsAllSelect()
            this.punishDetailTable.forEach(item => {
                item.isCheck = isAllSelect
                this.$refs.multipleTable.toggleRowSelection(item, !isAllSelect)
                this.selectFun(selection, item)
            })
        },
        //表格标题样式 当一级目录有为不明确状态时，添加样式，使其全选复选框为不明确状态样式
        headerRowClassName () {
            let oneProductIsSelect = []
            this.punishDetailTable.forEach(item => {
                oneProductIsSelect.push(item.isCheck)
            })
            if (oneProductIsSelect.includes('')) {
                return 'indeterminates'
            }
            return ''
        },

        // //表格样式当当前行的状态为不明确状态时，添加样式，使其复选框为不明确状态样式
        rowClassNameFun ({ row }) {
            if (row.isCheck === null) {
                return 'indeterminates'
            }
        },
        ...mapMutations(['setPopConfirm']),
        //获取类型选择框数据
        getTypeData () {
            call.getCredentialTree({ name: '外包方类型', id: '0' }).then(
                res => {
                    let id = ''
                    // 获取想要的类型id
                    res.map(item => {
                        if (item.kvKey == '分包商') {
                            id = item.kvId
                        }
                    })
                    call.getCredentialTree({ name: '外包方类型', id: id }).then(
                        res => {
                            this.typeList = res
                        }
                    )
                }
            )
            call.getCredential('信用评价类型').then(res => {
                let data = res.filter(item => {
                    return item.kvKey == '奖励' || item.kvKey == '惩罚'
                })
                this.rewardsOrPunishmentList = data
            })
        },
        //获取基本信息数据
        async getBasicData () {
            let data = await subcontractorRAP.GetSubcontractorRAP({
                id: this.billid
            })
            console.log(1111, data)
            data.outerTypeKey = data.outerTypeKey.split(',')
            data.outerTypeValue = data.outerTypeValue.split(',')
            if (data.endDate) {
                if (data.endDate.split('-')[0] == '9999') {
                    this.isLifelong = false
                }
            }
            // 如果是库外单位，则将奖励禁用，只能选择惩罚
            if (data.isOuterUnit) {
                this.rewardsOrPunishmentList.map(item => {
                    if (item.kvValue == '2') {
                        item.disabled = true
                    }
                })
            }
            this.basicFormData = data
            this.getCreditTemplate() //获取信用评价明细
        },
        // 通过分包商查模板
        async getCreditTemplateInformation (data) {
            let datas = await creditTemplate(data) //获取惩罚列表数据
            // 惩罚
            this.punishDetailTable = datas.punishmentDetails
            // 初始化惩罚数据的选中状态
            this.initData(this.punishDetailTable)
            // 奖励
            this.rewardData = datas.rewardDetails
            // 等模板请求成功再查询详情数据
        },
        // 获取信用评价明细
        async getCreditTemplate () {
            let datas = await subcontractorRAP.getCreditTemplate({
                id: this.billid
            })
            console.log(2222, datas)
            // 有数据，用后端返回数据
            if (datas.code != 200) {
                this.punishDetailTable = datas.punishmentDetails
                this.rewardData = datas.rewardDetails
                this.punishDetailTable.map(item => {
                    // 如果有子集，并且父组件不为false，则子组件也要进行选中
                    if (item.isCheck != false && item.children.length) {
                        item.children.map(childrenItem => {
                            this.$nextTick(function () {
                                this.$refs.multipleTable.toggleRowSelection(
                                    childrenItem,
                                    childrenItem.isCheck
                                )
                            })
                        })
                    }
                    // 父组件选中
                    this.$nextTick(function () {
                        this.$refs.multipleTable.toggleRowSelection(
                            item,
                            item.isCheck
                        )
                    })
                })
            } else {
                // 无数据,查信用模板
                this.getCreditTemplateInformation(
                    this.basicFormData.outerTypeValue
                )
            }
        },
        //获取惩罚列表数据
        async getCreditEvaluationType () {
            this.creditEvaluationTypeTable = await creditEvaluationType({
                type: '0'
            })
        },
        // 获取最后一个内容区域的高度，计算底部空白
        getLastConHeight () {
            let si = setInterval(() => {
                // 因为dom异步加载，通过轮询找到渲染后的dom，获取高度
                if (document.getElementById('auditHistory')) {
                    const lastConHeight =
                        document.getElementById('auditHistory').offsetHeight
                    this.lastConHeight = lastConHeight
                    clearInterval(si)
                    si = null
                }
            }, 100)
        },
        ctDelete () {
            this.clientPop('info', this.oneDeleteErr, this.delData)
        },
        //删除
        delData () {
            this.$Ajax
                .httpGet({
                    url: '/outer/rewardsorpunishment/delete',
                    params: {
                        id: this.billid
                    },
                    headers: {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                })
                .then(res => {
                    if (res.code == 200) {
                        showSuccessPop('删除成功！')
                        this.isSkip = true
                    }
                    this.$router.push('./subcontractorAward')
                })
        },
        //奖惩类型更改
        onRAPType (e, val) {
            // 如果是库外单位，则不能进行切换，只能为惩罚
            if (!this.basicFormData.isOuterUnit) {
                // 点当前选中的数据则不进判断
                if (this.basicFormData.rewardsOrPunishmentName != val) {
                    // 阻止click的默认事件，防止请求两次。
                    e.preventDefault()
                    // 判断有没有奖惩等级，有奖惩等级则提示，没有则直接切换
                    if (this.basicFormData.score) {
                        this.clientPop(
                            'info',
                            '奖惩等级或分数存在数据，是否切换奖惩类型？切换后数据将会被清空，请谨慎操作！',
                            this.callback(val)
                        )
                    } else {
                        this.basicFormData.rewardsOrPunishmentName = val
                    }
                }
            }
        },
        // 奖惩回调
        callback (e) {
            return () => {
                // 切换之后奖惩等级清空
                this.basicFormData.score = ''
                // 惩罚置空
                this.penaltyDetails = [{ id: this.billid }]
                // 奖励置空
                this.rewardData.map(item => {
                    item.scoreResult = ''
                    if (item.children) {
                        item.children.map(cheildrenItem => {
                            cheildrenItem.scoreResult = ''
                        })
                    }
                })
                this.basicFormData.rewardsOrPunishmentName = e
                //调用奖惩清空接口
                this.rewardsAndPunishmentsEmpty()
                // 调用基本信息接口，
                this.baseSave()
            }
        },
        //保存
        async save () {
            this.baseSend()
            // 奖惩
            this.Required()
            this.errorList = []
            if (this.isSend && this.isRequired) {
                Promise.all([this.baseSave(), this.rewardsAndPunishmentsSave()])
                    .then(async () => {
                        this.clientPop('suc', '保存成功')
                    })
                    .catch(err => {
                        this.clientPop(err, '保存失败')
                        this.scorllError()
                    })
            }
        },
        // 验证必填
        baseSend () {
            this.$refs.basicFormData.validate(async valid => {
                if (valid) {
                    // 验证附件必填
                    if (this.basicFormData.rewardsOrPunishmentName == '惩罚') {
                        if (this.$refs.accessory.attachTableData.length > 0) {
                            this.isSend = true
                            this.errorMsg = []
                        } else {
                            this.setError('accessory')
                            this.errorMsg.push('附件未上传')
                        }
                    } else {
                        this.isSend = true
                    }
                } else {
                    this.setError('baseInfo')
                    this.isSend = false
                    return false
                }
            })
        },
        // 基本数据保存
        async baseSave () {
            let data = JSON.parse(JSON.stringify(this.basicFormData))
            data.outerTypeKey = data.outerTypeKey.join(',')
            data.outerTypeValue = data.outerTypeValue.join(',')
            return new Promise((resolve, reject) => {
                subcontractorRAP
                    .UpdateSubcontractorRAP(data)
                    .then(() => {
                        resolve('基础数据保存成功')
                        // 刷新页面
                        this.getBasicData()
                    })
                    .catch(err => {
                        this.setError('baseInfo')
                        reject('基础数据保存失败', err)
                    })
            })
        },
        //清空惩罚单独调接口。不然会和修改删除接口冲突
        rewardsAndPunishmentsEmpty () {
            return new Promise((resolve, reject) => {
                // 奖惩接口
                subcontractorRAP
                    .updateCreditTemplate(this.penaltyDetails)
                    .then(() => {
                        resolve()
                        // 刷新页面
                        this.getCreditTemplate()
                    })
                    .catch(err => {
                        this.setError('baseInfo')
                        reject(err)
                    })
            })
        },
        //奖惩保存
        async rewardsAndPunishmentsSave () {
            // 惩罚明细保存
            let newPenaltyDetails = []
            // 奖励明细保存
            let newRewardData = []
            if (this.basicFormData.rewardsOrPunishmentName == '奖励') {
                // 奖励明细保存
                newRewardData = JSON.parse(JSON.stringify(this.rewardData))
                newRewardData.map(item => {
                    if (item.children) {
                        item.children.map(newItem => {
                            newItem.id = this.billid
                            newItem.changeType = 1
                        })
                    }
                    item.changeType = 1
                    item.id = this.billid
                })
            } else {
                // 惩罚明细保存
                newPenaltyDetails = JSON.parse(
                    JSON.stringify(this.punishDetailTable)
                )
                // // 如果有数据则添加id保存
                if (newPenaltyDetails.length > 0) {
                    newPenaltyDetails.map(item => {
                        if (item.children) {
                            item.children.map(newItem => {
                                newItem.id = this.billid
                            })
                        }
                        item.id = this.billid
                    })
                } else {
                    // 如果没有数据则传id
                    newPenaltyDetails = [{ id: this.billid }]
                }
            }
            return new Promise((resolve, reject) => {
                // 奖惩接口
                subcontractorRAP
                    .updateCreditTemplate(
                        this.basicFormData.rewardsOrPunishmentName == '奖励'
                            ? newRewardData
                            : newPenaltyDetails
                    )
                    .then(() => {
                        resolve('奖惩保存成功')
                        // 刷新页面
                        // this.getCreditTemplate()
                    })
                    .catch(err => {
                        this.setError('baseInfo')
                        reject('奖惩保存失败', err)
                    })
            })
        },
        //提交
        submit () {
            this.baseSend()
            // 奖惩
            this.Required()
            this.errorList = []
            if (this.isSend && this.isRequired) {
                Promise.all([this.baseSave(), this.rewardsAndPunishmentsSave()])
                    .then(async () => {
                        this.commit.billId = this.billid
                        subcontractorChange.findcommit(this.commit).then(() => {
                            this.clientPop('suc', '提交成功')
                            // 保存成功置空数据
                            this.$router.replace('/subcontractorAward')
                        })
                    })
                    .catch(() => {
                        this.clientPop('err', '提交失败')
                        this.scorllError()
                    })
            }
        },
        handleFullScreen () {
            this.fullscreen = !this.fullscreen
        },
        //取消
        handleClose () {
            this.$router.push('./subcontractorAward')
        },
        cellClsNm ({ column }) {
            if (column.label === '') {
                return 'fixed-left'
            }
        },
        cellMouseEnter (row) {
            this.MouseEnterId = row.id
        },
        cellMouseLeave () {
            this.MouseEnterId = 0
        },
        onChangeTab (e) {
            const height = $('#' + e.name).offset().top
            $.scrollTo(height - this.topHeight, 500)
            // 如果手动点击时，则不做滚动事件逻辑，只有滚动屏幕时才走滚动事件逻辑
            this.clickTabFlag = true
            // 动画结束后，恢复状态
            setTimeout(() => {
                this.clickTabFlag = false
            }, 600)
        },
        // handleSelectionChange (val) {
        //     this.multipleSelection = val
        // },
        //日期转换格式
        getTime (dt) {
            var year = dt.getFullYear() //年
            var month = dt.getMonth() + 1 //月
            var date = dt.getDate() //日
            month = month < 10 ? '0' + month : month
            date = date < 10 ? '0' + date : date
            var str = year + '-' + month + '-' + date
            return str
        },
        // 外包方类型全选
        handleCheckAllChange (val) {
            this.basicFormData.outerTypeValue = []
            this.basicFormData.outerTypeKey = val
                ? this.typeList.map(item => {
                    return item.kvKey
                })
                : []
            this.isIndeterminate = false
            // 循环拿到id
            this.typeList.map(item => {
                this.basicFormData.outerTypeValue.push(item.kvValue)
            })
        },
        //外包方类型选择
        handleCheckedCitiesChange (value) {
            this.basicFormData.outerTypeValue = []
            let checkedCount = value.length
            this.checkAll = checkedCount === this.typeList.length
            this.isIndeterminate =
                checkedCount > 0 && checkedCount < this.typeList.length
            // 循环拿到id
            this.typeList.map(item => {
                value.map(Valitem => {
                    if (item.kvKey == Valitem) {
                        this.basicFormData.outerTypeValue.push(item.kvValue)
                    }
                })
            })
            // 更改类型，则重新请求模板
            this.getCreditTemplateInformation(
                this.basicFormData.outerTypeValue
            )
        },
        // 选择惩戒的方法
        selectionClick () {
            // 将开始时间转换为时间格式-用于计算结束时间
            if (this.basicFormData.startDate) {
                this.basicFormData.startDate = this.formatDateTime(
                    this.basicFormData.startDate
                )
                let num = [] //存入选中的惩罚
                // 用原数组的是否选中字段来判断当前哪些数据被选中，将选中的数据push到num进行逻辑判断
                this.punishDetailTable.map(item => {
                    if (item.children) {
                        item.children.map(childrenItem => {
                            if (childrenItem.isCheck) {
                                if (childrenItem.parentId == item.dtlId) {
                                    num.push(item.dtlName)
                                }
                            }
                        })
                    } else {
                        if (item.isCheck) {
                            num.push(item.dtlName)
                        }
                    }
                })
                //奖惩等级或得分字段赋值
                /**
                 * 先判断是否惩戒终身，如果终身则直接变成终身，时间赋值为最大
                 * 如果不是终身，再判断是不是含有D级，有D级，则用三目判断，
                 * D级时间长还是安全联合惩戒时间更长，取时间更长的惩罚
                 */
                if (num.includes('安全联合惩戒终身年')) {
                    // 如果选择了终身，则隐藏时间组件，结束时间直接赋值9999年
                    this.isLifelong = false
                    this.basicFormData.score = 'D级'
                    this.basicFormData.endDate = '9999-12-30'
                } else if (num.includes('D级')) {
                    this.isLifelong = true
                    this.basicFormData.score = 'D级'
                    var year3 =
                        parseInt(this.basicFormData.startDate.split('-')[0]) +
                        parseInt(this.creditEvaluationTypeTable.blackDate) //年
                    var month3 = this.basicFormData.startDate.split('-')[1] //月
                    var date3 = this.basicFormData.startDate.split('-')[2] //日
                    var str3 = year3 + '-' + month3 + '-' + date3
                    this.basicFormData.endDate = str3
                } else if (num.includes('安全联合惩戒3年')) {
                    // 判断如果C级年限小于3年，则设置成3年
                    this.isLifelong = true
                    this.basicFormData.score = 'C级'
                    var year2 =
                        parseInt(this.basicFormData.startDate.split('-')[0]) +
                        3 //年
                    var month2 = this.basicFormData.startDate.split('-')[1] //月
                    var date2 = this.basicFormData.startDate.split('-')[2] //日
                    var str2 = year2 + '-' + month2 + '-' + date2
                    this.basicFormData.endDate = str2
                } else if (num.includes('安全联合惩戒1年')) {
                    // 判断如果C级年限小于一年，则设置成1年
                    this.isLifelong = true
                    this.basicFormData.score = 'C级'
                    var year1 =
                        parseInt(this.basicFormData.startDate.split('-')[0]) +
                        1 //年
                    var month1 = this.basicFormData.startDate.split('-')[1] //月
                    var date1 = this.basicFormData.startDate.split('-')[2] //日
                    var str1 = year1 + '-' + month1 + '-' + date1
                    this.basicFormData.endDate = str1
                } else if (num.includes('C级')) {
                    this.isLifelong = true
                    this.basicFormData.score = 'C级'
                    var year4 =
                        parseInt(this.basicFormData.startDate.split('-')[0]) +
                        parseInt(this.creditEvaluationTypeTable.offDate) //年
                    var month4 = this.basicFormData.startDate.split('-')[1] //月
                    var date4 = this.basicFormData.startDate.split('-')[2] //日
                    var str4 = year4 + '-' + month4 + '-' + date4
                    this.basicFormData.endDate = str4
                } else {
                    // 如果所有惩罚数据清空，则等级也清空
                    this.isLifelong = true
                    this.basicFormData.score = ''
                    this.basicFormData.endDate = new Date()
                }
            } else {
                this.clientPop('err', '请先选择开始时间')
            }
        },
        // 计算父级的实际分值
        calculation () {
            let nums = 0
            this.rewardData.map(item => {
                // 初始化子集分数
                let num = 0
                if (item.children) {
                    item.children.map(childrenitem => {
                        if (childrenitem.scoreResult <= childrenitem.score) {
                            if (childrenitem.scoreResult != null) {
                                num += parseInt(childrenitem.scoreResult)
                            }
                        } else {
                            this.clientPop(
                                'err',
                                '实得分数大于规定分数,请重新输入'
                            )
                            return (childrenitem.scoreResult = 0)
                        }
                    })
                    this.$set(item, 'scoreResult', num)
                }
                if (item.scoreResult <= item.score) {
                    if (!isNaN(parseInt(item.scoreResult))) {
                        nums += parseInt(item.scoreResult)
                    }
                } else {
                    this.clientPop('err', '实得分数大于规定分数,请重新输入')
                    return (item.scoreResult = 0)
                }
            })
            this.basicFormData.score = nums
        },
        // 分包商弹窗选择详情
        onFbUnit () {
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken: 'GeneralSelectOuter', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                InitParamsStr: JSON.stringify({
                    businessUnitTypes: [], //外来单位类型
                    keyword: '', //模糊查询关键字
                    limit: 10, //每页显示条数
                    orgId: '', //单据机构
                    outerTypes: [], //	外包方类型
                    page: 1, //当前页数
                    states: [], //单据状态
                    type: [0] //类型（0分包商 1供应商 2 往来单位 3 事实外包方）
                }),
                Title: '分包商选择'
            }).then(val => {
                // 保存用户选择返回数据到store
                this.isDisable = true
                this.formData.outerName = val[0].outerName
                this.formData.outerId = val[0].outerId
                this.formData.creditCode = val[0].creditCode
                this.formData.outerTypeKey = val[0].outerType.split(',')
                this.formData.outerTypeValue = val[0].outerTypeValue.split(',')
                // 查回来了就是库内单位
                this.formData.isOuterUnit = false //是否是库外单位
                // 禁用与启用奖惩类型
                this.rewardsOrPunishmentList.map(item => {
                    if (item.kvValue == '2') {
                        item.disabled = false
                        this.formData.rewardsOrPunishment = ''
                        this.formData.rewardsOrPunishmentName = ''
                    }
                })
            })
        },
        // 分包商名称验证
        async outerNameChange (val) {
            if (val) {
                let data = await getBaseName({ subcontractorName: val })
                if (data.id) {
                    this.basicFormData.outerId = data.id //分包商id
                    this.basicFormData.creditCode = data.creditCode
                    this.basicFormData.outerTypeKey =
                        data.subcontractorTypeKey.split(',')
                    this.basicFormData.outerTypeValue =
                        data.subcontractorTypeValue.split(',')
                    this.basicFormData.score = data.isQualified
                    this.isDisable = true
                    // 禁用与启用奖惩类型
                    this.rewardsOrPunishmentList.map(item => {
                        if (item.kvValue == '2') {
                            item.disabled = false
                            this.basicFormData.rewardsOrPunishment = ''
                            this.basicFormData.rewardsOrPunishmentName = ''
                        }
                    })
                    // 查回来了就是库内单位
                    this.basicFormData.isOuterUnit = false //是否是库外单位
                } else {
                    this.basicFormData.outerId = ''
                    this.basicFormData.creditCode = ''
                    this.basicFormData.outerTypeKey = []
                    this.basicFormData.outerTypeValue = []
                    this.basicFormData.score = ''
                    this.isDisable = false
                    this.basicFormData.isOuterUnit = true //是否是库外单位
                    // 禁用与启用奖惩类型
                    this.rewardsOrPunishmentList.map(item => {
                        if (item.kvValue == '2') {
                            item.disabled = true
                            this.basicFormData.rewardsOrPunishment = '1'
                            this.basicFormData.rewardsOrPunishmentName = '惩罚'
                        }
                    })
                }
            }
        },
        // 验证是否填了数据
        Required () {
            if (this.basicFormData.rewardsOrPunishmentName == '奖励') {
                if (this.basicFormData.score > 0) {
                    this.isRequired = true
                    this.errorMsg2 = []
                } else {
                    this.isRequired = false
                    this.setError('rewardDetails')
                    this.errorMsg2.push('至少填写一种奖励')
                    this.scorllError()
                }
            } else {
                let data = []
                // 用原数组的是否选中字段来判断当前哪些数据被选中
                this.punishDetailTable.map(item => {
                    if (item.children) {
                        item.children.map(childrenItem => {
                            data.push(childrenItem.isCheck)
                        })
                    }
                    data.push(item.isCheck)
                })
                // 如果包含true就证明选择的有数据
                if (data.includes(true)) {
                    this.isRequired = true
                    this.errorMsg1 = []
                } else {
                    this.isRequired = false
                    this.setError('punishDetail')
                    this.errorMsg1.push('至少选择一种惩罚')
                    this.scorllError()
                }
            }
        },
        // 合同名称查询
        onContract () {
            // 弹窗选择数据
            selectDataClient({
                SelectServiceToken:
                    '/subcontract/thirdParty/getSupplierContractInfosByOrgId', // 客户端对应方法名
                IsSingleMode: true, // 是否单选 true 单选 false 多选
                SelectedIDs: [], // 已选中id
                InitParamsStr: JSON.stringify({
                    types: [1] //合同类型集合，1：分包合同，2：机材支出合同
                }), //参数
                Title: '分包商合同选择'
            }).then(val => {
                // 保存用户选择返回数据到store
                this.basicFormData.contractName = val[0].contractName
                this.contractId = val[0].contractId //合同id
                this.type = val[0].type //合同类型
            })
        },
        // 分包商页面
        onSelect1 () {
            openAppClient(
                `/subcontractorExamine?isview=true&creditCode=${this.basicFormData.creditCode}`,
                '分包商详情',
                function () {}
            )
        },
        // 供应商合同页面
        onSelect2 () {
            openAppClient(
                    `//subcontractList?isview=true&billid=${this.contractId}`,
                    '分包合同详情',
                    function () {}
            )
        },
        // 审核历史列表查询
        async getAuditHistory () {
            let data = await subcontractorChange.findByIdAuditHistory({
                billId: this.billid,
                billType: 6046,
                freeNextUnitIndex: 0,
                freeNextUser: '',
                isPass: true,
                isShareInAudit: true,
                opinion: ''
            })
            this.tableData = data
        },
        // 获取按钮状态
        getCurrentUnitInfo () {
            examine
                .getCurrentUnitInfo({
                    billId: this.billid,
                    billType: 6046,
                    freeNextUnitIndex: 0,
                    freeNextUser: '',
                    isPass: true,
                    isShareInAudit: true,
                    opinion: ''
                })
                .then(res => {
                    this.auditState = res
                })
        },
        // 时间转换
        formatDateTime (inputTime) {
            var date = new Date(inputTime)
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            m = m < 10 ? '0' + m : m
            var d = date.getDate()
            d = d < 10 ? '0' + d : d
            var h = date.getHours()
            h = h < 10 ? '0' + h : h
            var minute = date.getMinutes()
            var second = date.getSeconds()
            minute = minute < 10 ? '0' + minute : minute
            second = second < 10 ? '0' + second : second
            return (
                y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second
            )
        },
        //设置错误标签
        setError (name) {
            if (!this.errorList.find(x => x === name)) {
                this.errorList.push(name)
            }
        },
        // 作废
        toVoidChange () {
            this.clientPop('info', '是否确认作废', this.callbacks)
        },
        // 作废确认回调
        async callbacks () {
            // 客户端弹窗弹出本地页面
            const auditParams = JSON.parse(localStorage.vuex).auditParams
            openAppClient('/nullifyDialog', '单据作废原因', async () => {
                showLoading()
                await toVoid({
                    billId: this.billid, //单据id
                    billType: '6046', //单据类型
                    nullifyCreated: '',
                    nullifyCreator: '',
                    nullifyCreatorId: '',
                    nullifyDescription: auditParams.nullifyDescription,
                    nullifyReason: auditParams.nullifyReason
                }).catch(() => {
                    this.clientPop('suc', '作废失败')
                })
                hideLoading()
            })
        },
        //跳转到第一个错误标签
        scorllError () {
            let num = this.tabArr.length
            this.errorList.forEach(item => {
                let index = this.tabArr.findIndex(x => x === item)
                num = index < num ? index : num
            })
            const obj = { name: this.tabArr[num] }
            this.tabsName = this.tabArr[num]
            this.onChangeTab(obj)
        },
        // 按钮组件触发事件
        exas (data) {
            switch (data) {
            case 'audit':
                this.audit() //审核
                break
            case 'undoAudit':
                this.withdrawChange() //撤回
                break
            case 'submitCommit':
                this.submit() //提交
                break
            case 'submit':
                this.save() //保存
                break
            case 'nullify':
                this.toVoidChange() //作废
                break
            case 'deleteData':
                this.ctDelete() //删除
                break
            default:
                break
            }
        }
    }
}
</script>

<style lang="scss" scoped>
// .buttons {
//   left: 0;
// }
// .e-form {
//   margin-bottom: 80px;
//   padding: 0 20px;
//   .tabs-title::before {
//     content: "";
//     height: 22px;
//     width: 8px;
//     border-radius: 40px;
//     background-color: #2e61d7;
//     display: block;
//     position: absolute;
//     left: 20px;
//     margin-right: 20px;
//   }
// }

// .e-table {
//   background: #fff;
// }
// ::v-deep.el-table__body-wrapper::-webkit-scrollbar{
//      width: 6px !important; // 横向滚动条
//     height: 10px !important// 纵向滚动条
// }

// ::v-deep .el-table__body-wrapper::-webkit-scrollbar {
//   width: 6px; // 横向滚动条
//   height: 10px; // 纵向滚动条
// }
// // 滚动条的滑块
// ::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
//   background-color: #ddd;
//   border-radius: 5px;
// }

// .el-tab-pane {
//   margin-left: -10px;
// }
::v-deep .indeterminates .el-checkbox__input .el-checkbox__inner {
    background-color: #409eff !important;
    border-color: #409eff !important;
    color: #fff !important;
}

::v-deep
    .indeterminates
    .el-checkbox__input.is-checked
    .el-checkbox__inner::after {
    transform: rotate(45deg) scaleY(0) !important;
}

::v-deep .indeterminates .el-checkbox__input .el-checkbox__inner {
    background-color: #f2f6fc;
    border-color: #dcdfe6;
}
::v-deep .indeterminates .el-checkbox__input .el-checkbox__inner::after {
    border-color: #c0c4cc !important;
    background-color: #c0c4cc;
}
::v-deep .multipleTable-show th .el-checkbox__inner {
    display: none !important;
}

::v-deep .indeterminates .el-checkbox__input .el-checkbox__inner::after {
    content: '';
    position: absolute;
    display: block;
    background-color: #fff;
    height: 2px;
    transform: scale(0.5);
    left: 0;
    right: 0;
    top: 5px;
    width: auto !important;
}
// .el-checkbox__input.is-checked .el-checkbox__inner::after{
//     transform: rotate(45deg) scaleY(0) !important
// }
.multipleTable-show .el-checkbox__inner {
    display: block !important;
}

.multipleTable-show .el-checkbox {
    display: block !important;
}
</style>
